<template>
  <div style="display: flex;align-items: center;justify-content: center;">
    <el-card shadow="always" style="width: 40%; margin: 10px">
      <el-form label-width="80px" :model="From">
        <el-form-item label="">
          <el-upload class="avatar-uploader" action="http://localhost:8080/users/updateHeadPortrait"
                     :show-file-list="false" :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload"
                     :data={userId:this.id}>
            <el-button type="primary" style="margin-left: 20px">修改头像</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="当前用户:">
          <el-input v-model="From.name"></el-input>
        </el-form-item>
        <el-form-item label="登陆账号:">
          <el-input v-model="From.userId" disabled></el-input>
        </el-form-item>
        <el-form-item label="密码:">
          <el-input v-model="From.password" type="password" show-password></el-input>
        </el-form-item>
        <el-form-item label="性别:">
          <el-radio v-model="From.sex" label="男">男</el-radio>
          <el-radio v-model="From.sex" label="女">女</el-radio>
        </el-form-item>
        <el-form-item label="年龄:">
          <el-input v-model="From.age" placeholder="用户年龄"></el-input>
        </el-form-item>
        <el-form-item label="身份:">
          <el-input v-model="From.identity" disabled></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="warning" style="width: 150px;" @click="onEdit()">修改</el-button>
          <el-button type="success" style="width: 150px;" @click="$router.push('/RevenueDetails')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import Cookie from "cookie_js";
import request from "../../utils/request";

export default {
  name: "Person",
  components:{},
  created() {
    this.findByUser()
  },
  data(){
    return{
      //表单
      From:{}
    }
  },
  methods:{
    //查询用户数据
    findByUser(){
      request.get("/user/findUserById/"+Cookie.get("userId")).then(res => {
       if(res!=null){
         this.From = res
       }
      })
    },
    //修改个人信息
    onEdit(){
      request.post("/user/onEditByEntity",this.From).then(res => {
        if(res.code==="0"){
          this.$message({
            type: "success",
            message: res.msg
          })
        }else {
          this.$message({
            type: "error",
            message: res.msg
          })
        }
        //刷新当前表格
        this.findByUser()
      })
    }
  }
}
</script>

<style scoped>

</style>